import threading
import time


lock = threading.Lock()
num = 0

def add_num():
    global num
    # 获取锁
    # lock.acquire() 
    num += 1
    time.sleep(1)
    # 释放锁
    # lock.release()

def main():
    threads = []

    for i in range(1000):
        t = threading.Thread(target=add_num)
        threads.append(t)
    
    for i in range(1000):
        threads[i].start()

    for i in range(1000):
        threads[i].join()

    print('num:', num)

if __name__ == "__main__":
    main()